package com.zhangwei.expands.utils;

import android.widget.BaseAdapter;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.zhangwei.expands.bean.ComApiBean;

import java.util.List;

import cn.finalteam.okhttpfinal.HttpRequest;
import cn.finalteam.okhttpfinal.RequestParams;
import cn.finalteam.okhttpfinal.StringHttpRequestCallback;

/**
 * @version V1.0
 * @description:
 * @title: Expands
 * @package com.zhangwei.expands.utils
 * @author: zhangwei
 * @date: 2015-12-23 上午11:09
 */
public class HttpUtils {
    public static void post(String url, RequestParams params, final List<?> list, final BaseAdapter adapter, final TypeReference type) {
        HttpRequest.post(url, params, new StringHttpRequestCallback() {

            @Override
            public void onFinish() {
                super.onFinish();
            }

            /**
             * javaben里如果有泛型 就不能使用.class
             * @param s
             */
            @Override
            protected void onSuccess(String s) {
                super.onSuccess(s);
                //解析
                ComApiBean bean = (ComApiBean) JSONObject.parseObject(s, type);
                if (bean != null && bean.getInfo() != null) {
                    list.addAll(bean.getInfo());
                    adapter.notifyDataSetChanged();
                }
                //adater刷新


            }

            @Override
            public void onFailure(int errorCode, String msg) {
                super.onFailure(errorCode, msg);
            }
        });


    }


}
